package Test;

import static org.junit.Assert.*;

import java.util.ArrayList;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import Pointers.OffsetRangeGenerator;
import Script.Offset;

public class OffsetRangeGeneratorTest {
	
	@Test
	public void canGenerateSinglePointerFromOffsetZero() {
		OffsetRangeGenerator g = new OffsetRangeGenerator(
				new Offset(0), new Offset(2), 2, 0);
		ArrayList<Offset> list = g.getOffsets();
		
		assertEquals(list.size(), 1);
	}
	
	@Test
	public void canDetectIfEndOffsetIsNotEqualOrHigherThanStartOffset() {
		OffsetRangeGenerator g = new OffsetRangeGenerator(
										new Offset(3), new Offset(2), 0, 0);
		
		assertEquals(g.getOffsets(), null);
	}
	
	@Test
	public void invalidatesIfByteSizeIsZero() {
		OffsetRangeGenerator g = new OffsetRangeGenerator(
										new Offset(1), new Offset(2), 0, 0);
		
		assertEquals(g.getOffsets(), null);
	}
	
	@Test
	public void invalidatesIfByteSpaceIsLowerThanZero() {
		OffsetRangeGenerator g = new OffsetRangeGenerator(
										new Offset(1), new Offset(2), 1, -1);
		
		assertEquals(g.getOffsets(), null);
	}
	
	@Test
	public void invalidatesIfNumberOfPointersIsFloatingPoint() {
		OffsetRangeGenerator g = new OffsetRangeGenerator(
										new Offset(1), new Offset(9), 3, 0);
		
		assertEquals(g.getOffsets(), null);
	}
	
	@Test
	public void validatesIfNumberOfPointersIsInteger() {
		OffsetRangeGenerator g = new OffsetRangeGenerator(
										new Offset(1), new Offset(9), 2, 0);
		
		assertTrue(g.getOffsets() != null);
	}
	
	@Test
	public void validatesIfNumberOfPointersIsIntegerWithPointerSpace() {
		OffsetRangeGenerator g = new OffsetRangeGenerator(
										new Offset(1), new Offset(12), 2, 1);
		
		assertTrue(g.getOffsets() != null);
	}
	
	@Test
	public void validatesEvenIfNumberOfPointersIsOne() {
		OffsetRangeGenerator g = new OffsetRangeGenerator(
										new Offset(1), new Offset(2), 1, 0);
		
		assertTrue(g.getOffsets() != null);
	}
	
	/** 
	 * Testing data output
	 */
	
	@Test
	public void canGenerateSinlgeOffsetWithNoPointerSpace() {
		OffsetRangeGenerator g = new OffsetRangeGenerator(
										new Offset(1), new Offset(2), 1, 0);
		ArrayList<Offset> list = g.getOffsets();
		
		assertEquals(list.size(), 1);
		assertEquals(list.get(0).getValue(), 1);
	}
	
	@Test
	public void canGenerateMultipleOffsetsWithNoPointerSpace() {
		OffsetRangeGenerator g = new OffsetRangeGenerator(
										new Offset(1), new Offset(3), 1, 0);
		ArrayList<Offset> list = g.getOffsets();
		
		assertEquals(list.size(), 2);
		assertEquals(list.get(1).getValue(), 2);
	}
	
	@Test
	public void canGenerateMultipleOffsetsWithByteSize() {
		OffsetRangeGenerator g = new OffsetRangeGenerator(
										new Offset(1), new Offset(10), 3, 0);
		ArrayList<Offset> list = g.getOffsets();
		
		assertTrue(list.size() == 3);
		assertEquals(list.get(1).getValue(), 4);
	}
	
	@Test
	public void canGenerateMultipleOffsetsWithByteSpace() {
		OffsetRangeGenerator g = new OffsetRangeGenerator(
										new Offset(1), new Offset(12), 1, 4);
		ArrayList<Offset> list = g.getOffsets();
		
		assertEquals(list.size(), 3);
		assertEquals(list.get(2).getValue(), 11);
	}
	
	@Test
	public void canGenerateMultipleOffsetsWithByteSpaceAndByteSize() {
		OffsetRangeGenerator g = new OffsetRangeGenerator(
										new Offset(1), new Offset(67), 3, 4);
		ArrayList<Offset> list = g.getOffsets();
		
		assertTrue(list.size() == 10);
		assertEquals(list.get(1).getValue(), 8);
		assertEquals(list.get(9).getValue(), 64);
	}
	
}
